The good old clamp function, now part of the Math family.
Clamp is happy after so many years of loneliness.
This is a strict implementation of the draft ECMAScript
proposal.
https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1295
return name;
}
-function clamp(value, min, max) {
- return Math.max(min, Math.min(max, value));
-}
-
function _getViewFromIcon(icon) {
for (let parent = icon.get_parent(); parent; parent = parent.get_parent()) {
if (parent instanceof BaseAppView)
}
goToPage(pageNumber, animate = true) {
- pageNumber = clamp(pageNumber, 0, this._grid.nPages() - 1);
+ pageNumber = Math.clamp(pageNumber, 0, this._grid.nPages() - 1);
if (this._grid.currentPage === pageNumber &&
this._displayingDialog &&
const Format = imports.format;
String.prototype.format = Format.format;
+
+ Math.clamp = function (x, lower, upper) {
+ return Math.min(Math.max(x, lower), upper);
+ };
}
// adjustAnimationTime:
}
});
-function clamp(value, min, max) {
- return Math.max(Math.min(value, max), min);
-}
-
function zoomOutActor(actor) {
let [x, y] = actor.get_transformed_position();
zoomOutActorAtPos(actor, x, y);
let scaledHeight = height * APPICON_ANIMATION_OUT_SCALE;
let scaledX = x - (scaledWidth - width) / 2;
let scaledY = y - (scaledHeight - height) / 2;
- let containedX = clamp(scaledX, monitor.x, monitor.x + monitor.width - scaledWidth);
- let containedY = clamp(scaledY, monitor.y, monitor.y + monitor.height - scaledHeight);
+ let containedX = Math.clamp(scaledX, monitor.x, monitor.x + monitor.width - scaledWidth);
+ let containedY = Math.clamp(scaledY, monitor.y, monitor.y + monitor.height - scaledHeight);
actorClone.ease({
scale_x: APPICON_ANIMATION_OUT_SCALE,
}
});
-function clamp(value, min, max) {
- return Math.max(min, Math.min(max, value));
-}
-
var AppAuthorizer = class {
constructor(desktopId, reqAccuracyLevel, permStoreProxy, maxAccuracyLevel) {
this.desktopId = desktopId;
_completeAuth() {
if (this._accuracyLevel != GeoclueAccuracyLevel.NONE) {
- this._accuracyLevel = clamp(this._accuracyLevel,
- 0,
- this._maxAccuracyLevel);
+ this._accuracyLevel = Math.clamp(this._accuracyLevel,
+ 0, this._maxAccuracyLevel);
}
this._saveToPermissionStore();
SCROLLING: 1,
};
-function clamp(value, min, max) {
- return Math.max(min, Math.min(max, value));
-}
-
const TouchpadSwipeGesture = GObject.registerClass({
Properties: {
'enabled': GObject.ParamSpec.boolean(
let firstPoint = this._snapPoints[0];
let lastPoint = this._snapPoints[this._snapPoints.length - 1];
- this._progress = clamp(this._progress, firstPoint, lastPoint);
- this._progress = clamp(this._progress,
+ this._progress = Math.clamp(this._progress, firstPoint, lastPoint);
+ this._progress = Math.clamp(this._progress,
this._initialProgress - 1, this._initialProgress + 1);
this.emit('update', this._progress);
let duration = Math.abs((this._progress - endProgress) / velocity * DURATION_MULTIPLIER);
if (duration > 0) {
- duration = clamp(duration,
+ duration = Math.clamp(duration,
MIN_ANIMATION_DURATION, MAX_ANIMATION_DURATION);
}